class Storage {
    set(field: string, value) {
        if (typeof value === 'object') {
            localStorage.setItem(field, JSON.stringify(value));
        } else {
            localStorage.setItem(field, value);
        }
    }
    get(field: string) {
        let value = localStorage.getItem(field);
        if (typeof value !== 'string') {
            return value;
        } else {
            try {
                value = JSON.parse(value);
                return value;
            } catch (err) {
                return value;
            }
        }
    }
    remove(field: string) {
        localStorage.removeItem(field);
    }
}

export default new Storage();